package com.ldg.rocketmq.listener;

import com.alibaba.fastjson.JSON;
import com.ld.utils.SmsUtil;
import com.ldg.rocketmq.pojo.UserInfo;
import lombok.SneakyThrows;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 类名：
 * 作者：WF
 * 功能：监听发过来的手机验证码相关信息
 */
@Component
@RocketMQMessageListener(topic = "codeMsg",consumerGroup = "consumer-group2")
public class MyRocketmqListener02 implements RocketMQListener<String> {



	@Autowired
	private SmsUtil smsUtil;
	@SneakyThrows
	@Override
	public void onMessage(String userInfo) {

		//接收到消息并转换为UserInfo对象
		UserInfo user = JSON.parseObject(userInfo, UserInfo.class);
		System.out.println("user = " + user);
		//发送消息给阿里云
		smsUtil.sendSms(user.getAccessKey(),
						user.getAccessKeySecret(),
						user.getPhone(),
						user.getSignName(),
						user.getTemplateCode(),
						user.getTemplateParam());
	}
}

